import store from "./index"
import { appActionType } from "./modules/app"

export default {
  //是否自定播放单词读音
  getters: {
    getAutoAudioSetting() {
      const storage = uni.getStorageSync("autoAudioSetting")
      //如果取出的为空则默认设置为 false
      return storage === "true"
    },
  },
  setters: {
    setAutoAudioSetting(val) {
      if (val) {
        uni.setStorageSync("autoAudioSetting", "true")
      } else {
        uni.setStorageSync("autoAudioSetting", "false")
      }
    },
  },
  //听力音频播放速率
  hearingAudioPlaySpeedRate: {
    get() {
      const res = uni.getStorageSync("hearingAudioPlaySpeedRate")
      return res ? Number.parseInt(res) : 1
    },
    set(val) {
      uni.setStorageSync("hearingAudioPlaySpeedRate", val)
    },
  },
  //记住上次展开的刷题年份和试卷
  rememberLastQuestion: {
    set(val) {
      uni.setStorageSync("rememberLastQuestion", JSON.stringify(val))
    },
    get() {
      return uni.getStorageSync("rememberLastQuestion") ? JSON.parse(uni.getStorageSync("rememberLastQuestion")) : {}
    },
  },
  //视频播放倍速
  videoPlaySpeedRate: {
    set(val) {
      uni.setStorageSync("videoPlaySpeedRate", val)
    },
    get() {
      return uni.getStorageSync("videoPlaySpeedRate") ? Number.parseInt(uni.getStorageSync("videoPlaySpeedRate")) : 1
    },
  },
  //做题界面设置
  practiceSettings: {
    set(val) {
      uni.setStorageSync("practiceSettings", JSON.stringify(val))
    },
    get() {
      let val = uni.getStorageSync("practiceSettings")
      if (val) {
        return JSON.parse(val)
      } else {
        return {}
      }
    },
    setItem(key, val) {
      let settings = this.get()
      settings[key] = val
      this.set(settings)
    },
    getItem(key) {
      let settings = this.get()
      return settings[key]
    },
  },
  //是否弹过了新用户领取福利的弹窗
  newUserWelfareDialog: {
    set(val) {
      uni.setStorageSync("newUserWelfareDialog", val)
    },
    get() {
      return uni.getStorageSync("newUserWelfareDialog")
    },
  },
  //是否弹过了半屏显示指引
  hasShowEmbeddedGuidelines: {
    set(val) {
      uni.setStorageSync("hasShowEmbeddedGuidelines", val)
    },
    get() {
      return uni.getStorageSync("hasShowEmbeddedGuidelines")
    },
  },
  //资料领取活动页用户领取的资料
  userReceiveResource: {
    set(val) {
      uni.setStorageSync("userReceiveResource", val)
    },
    get() {
      return uni.getStorageSync("userReceiveResource")
    },
    add(val) {
      let list = this.get() || []
      list.push(val)
      this.set(list)
    }
  },
  //资料领取页面记录用户选择的考试
  userSelectExam: {
    set(val) {
      uni.setStorageSync("userSelectExam", val)
    },
    get() {
      return uni.getStorageSync("userSelectExam")
    },
  },
  //被邀请人的userId
  inviteUserId: {
    set(val) {
      uni.setStorageSync("inviteUserId", val)
    },
    get() {
      return uni.getStorageSync("inviteUserId")
    },
  },
  //分享类型
  shareType: {
    set(val) {
      uni.setStorageSync("shareType", val)
    },
    get() {
      return uni.getStorageSync("shareType")
    },
  },
  //分享人id
  shareUserId: {
    set(val) {
      uni.setStorageSync("shareUserId", val)
    },
    get() {
      return uni.getStorageSync("shareUserId")
    },
  },
}
